<#assign ctx=springMacroRequestContext.contextPath />
<#include "/macro/publicMacro.ftl">
<#import "/macro/pagination.ftl" as Pagination>
<#import "/macro/FormItem.ftl" as Form>

<@header title="编辑类目">
    <link href="${ctx}/resource/frame/layui/css/layui.css" rel="stylesheet">
</@header>

<@body>
<h2 class="module-title">编辑类目</h2>

<div class="alert alert-primary" role="alert">
    <button class="btn btn-info" onclick="javascript: history.back(-1);return false;" >返回</button>
</div>

<form class="form-horizontal" id="cmsCategoryForm" action="${ctx}/cmsCategory/save" method="post">
    <input type="hidden" name="id" value="${cmsCategory.id}"/>
    <@Form.FormItem name="tenantId" label="租户id">
        <select class="form-control" name="tenantId" id="tenantId">
            <#list tenants as tenant>
                <option value="${tenant.id}" <#if tenant.id == cmsCategory.tenantId>selected</#if>>${tenant.description}</option>
            </#list>
        </select>
    </@Form.FormItem>
    <@Form.FormItem name="name" label="类目名称">
        <input type="text" class="form-control" name="name" id="name" aria-describedby="类目名称" value="${cmsCategory.name}">
    </@Form.FormItem>
    <@Form.FormItem name="parentId" label="父类型${cmsCategory.parentId}">
        <input type="text" class="form-control" name="parentId" id="parentId" aria-describedby="父类型" value="${cmsCategory.parentId}">
    </@Form.FormItem>
    <@Form.FormItem name="description" label="类目描述">
        <input type="text" class="form-control" name="description" id="description" aria-describedby="类目描述" value="${cmsCategory.description}">
    </@Form.FormItem>
    <@Form.FormItem name="index" label="排序">
        <input type="text" class="form-control" name="index" id="index" aria-describedby="排序" value="${cmsCategory.index}">
    </@Form.FormItem>
    <@Form.FormItem name="enable" label="是否可用">
        <select class="form-control" name="enable" id="enable">
            <#list statusValues as status>
                <option value="${status}" <#if status == cmsCategory.status>selected</#if>>${status.desc}</option>
            </#list>
        </select>
    </@Form.FormItem>
    <div class="form-group">
        <div class="col-sm-offset-2 col-sm-10">
            <button type="submit" class="btn btn-primary">提交</button>
        </div>
    </div>
</form>
</@body>

<@footer>
    <script src="${ctx}/resource/common/js/jquery.validate.min.js"></script>
    <script src="${ctx}/resource/common/js/validate_zh.js"></script>
    <script src="${ctx}/resource/common/js/additional-methods.min.js"></script>
    <script src="${ctx}/resource/frame/layui/layui.js"></script>

    <script>
        layui.config({
            base: '${ctx}/resource/frame/treeSelect/'
        }).use(['treeSelect','form'], function () {
            var treeSelect= layui.treeSelect;

            treeSelect.render({
                // 选择器
                elem: '#parentId',
                // 数据
                data: '${ctx}/cmsCategory/list/json2',
                // 异步加载方式：get/post，默认get
                type: 'get',
                // 占位符
                placeholder: '请选择所属模块',
                // 是否开启搜索功能：true/false，默认false
                search: true,
                // 点击回调
                click: function(d){
                    console.log(d);
                },
                // 加载完成后的回调函数
                success: function (d) {
                    console.log(d);
                    if('${cmsCategory.parentId!}' != '') {
                        treeSelect.checkNode('parentId', ${cmsCategory.parentId});
                    }
                }
            });
        });
    </script>

    <script type="text/javascript">
        $().ready(function() {
            $("#cmsCategoryForm").validate({
                rules: {
                    id: {
                        required: true,
                        digits: true
                    },
                    tenantId: {
                        required: true,
                        digits: true
                    },
                    name: "required" ,
                    description: "required" ,
                    index: {
                        required: true,
                        digits: true
                    },
                    enable: {
                        required: true
                    }
                }
            });
        });
    </script>
</@footer>